package org.jeecg;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.ServerSocket;
import java.net.Socket;

public class WebServer {
	
	private ServerSocket serverSocket;

	public void serverStart(int port){
		try {
			serverSocket = new ServerSocket(port);
			System.out.println("--> 启动成功.");
			System.out.println("--> 等待访问......");
			while(true){
				Socket socket = serverSocket.accept();
				new Processor(socket).start();
			}
		} catch (IOException e) {
			System.out.println("--> error - 启动Socket失败。。。");
			e.printStackTrace();
		}
	}

	public static void main(String[] args) throws UnsupportedEncodingException {
		int port = 80;
		if(args.length == 1){
			port =  Integer.parseInt(args[0]);
		}
		new WebServer().serverStart(port);
	}

}
